﻿$(document).ready(function () {
    $('#summernote').summernote({
        lang: 'zh-CN',
        minHeight: 250,
        tabsize: 2,
        disableDragAndDrop: false,
        dialogsInBody: true,
        dialogsFade: true,
        codemirror: { // codemirror options
            lineNumbers: true,
            matchBrackets: true,
            styleActiveLine: true,
            extraKeys:{"Ctrl-Space":"autocomplete"},
            theme: "monokai"
        },
        toolbar: [
            ['style', ['style']],
            ['font', ['bold', 'underline', 'clear']],
            ['fontname', ['fontname']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['height', ['height']],
            ['table', ['table']],
            ['insert', ['link', 'picture', 'video']],
            ['view', ['fullscreen', 'codeview', 'help']],
            ['myplugin', ['aceCodeEditor']]
        ],
        
        callbacks: {
            onImageUpload: function (files, editor, welEditable) {
                sendFile(files[0], editor, welEditable);
            }
        }
    }); 
});


//文件上传
function sendFile(file, editor, welEditable) {
    var data = new FormData();
    data.append("file", file);
    $.ajax({
        data: data,
        type: "POST",
        processData: false,
        contentType: false,
        cache: false,
        url: '/Review/UpLoadImages',
        success: function (url) {
            $('#summernote').summernote('insertImage', url);         
        }
    });
};